rendericon: Pass the scale factor when rendeirng textures
authorBenjamin Otte <otte@redhat.com>
Sat, 26 Nov 2016 10:51:30 +0000 (11:51 +0100)
committerBenjamin Otte <otte@redhat.com>
Sat, 26 Nov 2016 10:52:30 +0000 (11:52 +0100)
Fixes icon rendeirng on hidpi.

gtk/gtkiconhelper.c
gtk/gtkrendericon.c
gtk/gtkrendericonprivate.h
gtk/gtksnapshot.c

index f3b66216a6aa3ea604129aa100407b3135fff762..fee8bd641d5e9a8a82062d0aad643e0996607f05 100644 (file)
@@ -871,7 +871,10 @@ gtk_icon_helper_snapshot (GtkIconHelper *self,
  
   style = gtk_css_node_get_style (gtk_css_gadget_get_node (GTK_CSS_GADGET (self)));
 
-  gtk_css_style_snapshot_icon_texture (style, snapshot, texture);
+  gtk_css_style_snapshot_icon_texture (style,
+                                       snapshot,
+                                       texture,
+                                       gtk_widget_get_scale_factor (gtk_css_gadget_get_owner (GTK_CSS_GADGET (self))));
 }
 
 gboolean
index 7355ebed2645117fffc4fadfc868810d1d98fe09..b20b743903293cb0335dba316ac99f07521caed1 100644 (file)
@@ -249,23 +249,25 @@ gtk_css_style_render_icon_get_extents (GtkCssStyle  *style,
 void
 gtk_css_style_snapshot_icon_texture (GtkCssStyle *style,
                                      GtkSnapshot *snapshot,
-                                     GskTexture  *texture)
+                                     GskTexture  *texture,
+                                     double       texture_scale)
 {
   const GtkCssValue *shadows, *transform;
-  graphene_matrix_t transform_matrix, m1, m2, m3, saved_matrix;
+  graphene_matrix_t transform_matrix, translate, matrix, saved_matrix;
   graphene_rect_t bounds;
   GskRenderNode *node;
-  int width, height;
+  double width, height;
   static gboolean shadow_warning;
 
   g_return_if_fail (GTK_IS_CSS_STYLE (style));
   g_return_if_fail (snapshot != NULL);
   g_return_if_fail (GSK_IS_TEXTURE (texture));
+  g_return_if_fail (texture_scale > 0);
 
   shadows = gtk_css_style_get_value (style, GTK_CSS_PROPERTY_ICON_SHADOW);
   transform = gtk_css_style_get_value (style, GTK_CSS_PROPERTY_ICON_TRANSFORM);
-  width = gsk_texture_get_width (texture);
-  height = gsk_texture_get_height (texture);
+  width = gsk_texture_get_width (texture) / texture_scale;
+  height = gsk_texture_get_height (texture) / texture_scale;
 
   if (!gtk_css_transform_value_get_matrix (transform, &transform_matrix))
     return;
@@ -273,13 +275,13 @@ gtk_css_style_snapshot_icon_texture (GtkCssStyle *style,
   graphene_matrix_init_from_matrix (&saved_matrix, gtk_snapshot_get_transform (snapshot));
 
   /* XXX: Implement -gtk-icon-transform-origin instead of hardcoding "50% 50%" here */
-  graphene_matrix_init_translate (&m1, &GRAPHENE_POINT3D_INIT(width / 2.0, height / 2.0, 0));
-  graphene_matrix_multiply (&transform_matrix, &m1, &m3);
-  graphene_matrix_init_translate (&m2, &GRAPHENE_POINT3D_INIT(- width / 2.0, - height / 2.0, 0));
-  graphene_matrix_multiply (&m2, &m3, &m1);
-  gtk_snapshot_transform (snapshot, &m1);
+  graphene_matrix_init_translate (&translate, &GRAPHENE_POINT3D_INIT(width / 2.0, height / 2.0, 0));
+  graphene_matrix_multiply (&transform_matrix, &translate, &matrix);
+  graphene_matrix_translate (&matrix, &GRAPHENE_POINT3D_INIT(- width / 2.0, - height / 2.0, 0));
+  graphene_matrix_scale (&matrix, 1.0 / texture_scale, 1.0 / texture_scale, 1);
+  gtk_snapshot_transform (snapshot, &matrix);
 
-  graphene_rect_init (&bounds, 0, 0, width, height);
+  graphene_rect_init (&bounds, 0, 0, gsk_texture_get_width (texture), gsk_texture_get_height (texture));
 
   node = gtk_snapshot_append (snapshot, &bounds, "Icon");
   if (!_gtk_css_shadows_value_is_none (shadows) && !shadow_warning)
index 6a3ca4b9119dd085b914fef685f9fe56c626a4e1..2ab38f76990763ee8c85f11a8b3f0afb4d9df255 100644 (file)
@@ -49,7 +49,8 @@ void    gtk_css_style_render_icon_surface       (GtkCssStyle            *style,
                                                  double                  y);
 void    gtk_css_style_snapshot_icon_texture     (GtkCssStyle            *style,
                                                  GtkSnapshot            *snapshot,
-                                                 GskTexture             *texture);
+                                                 GskTexture             *texture,
+                                                 double                  texture_scale);
 
 void    gtk_css_style_render_icon_get_extents   (GtkCssStyle            *style,
                                                  GdkRectangle           *extents,
index 99d7ea5e5a2344e10ea006550d15420ef9677989..5ec1d56aa9c861a39e85ffc7752324ba5ed9e370 100644 (file)
@@ -688,7 +688,8 @@ gtk_snapshot_render_icon (GtkSnapshot     *snapshot,
   gtk_snapshot_translate_2d (snapshot, x, y);
   gtk_css_style_snapshot_icon_texture (gtk_style_context_lookup_style (context),
                                        snapshot,
-                                       texture);
+                                       texture,
+                                       1);
   gtk_snapshot_translate_2d (snapshot, -x, -y);
   gsk_texture_unref (texture);
 }